package com.ruizhong.centercontroll.controller;


import com.alibaba.fastjson.JSONObject;
import com.ruizhong.centercontroll.util.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import java.io.*;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;

@RestController
@RequestMapping("/system/api")
@CrossOrigin
@Slf4j
public class SystemController {


    @GetMapping("/setVolume/{type}")
    public Result setVolume(@PathVariable(value = "type") String type) {
        SystemUtils.controlSystemVolume(type);
        return new Result(ResultCode.success, null, null);
    }

    @GetMapping("/playVideo")
    public Result playVideo() {
//        OpenGlUtil.drawVideo();
        return new Result(ResultCode.success, null, null);
    }

    @GetMapping("/shutdownMachine")
    public void shutdownMachine() {
        try {
            // Windows shutdown command
            String command = "shutdown /s /t 0";
            Process process = Runtime.getRuntime().exec(command);
            int exitCode = process.waitFor();
            System.out.println("Exited with code: " + exitCode);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @PostMapping("/speechToText")
    public void speechToText() throws IOException {
//        try {
//            String filePath = "temp.wav";
//            try (FileOutputStream fos = new FileOutputStream(filePath)) {
//                fos.write(audioData);
//            }
//            System.out.println("保存成功");
//        } catch (Exception e) {
//            e.printStackTrace();
//            System.out.println("保存失败");
//        }
//
//        VoiceToTextUtil.execModel(null);
//        File file = new File("temp.wav");
//        RecognizeAudioByBaidu.recognize(file);

    }

    @PostMapping("/stringToMap")
    public Result stringToMap(@RequestBody Map<String,Object> map) throws UnsupportedEncodingException {
        return new Result<>(ResultCode.success,null,map);
    }



}
